<style>
    .center{
        text-align:center;
    }
    .table-action-area{
        float: right;
    }
</style>
<div class="layui-fluid layui-anim website-anim" id="website-indicator-update" lay-title="评审标准选项管理编辑">
    <div class="layui-row website-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body website-table-full" id="table-view">
                    <form class="layui-form layui-table-form" lay-filter="standard-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md12">
                                <div class="layui-form-item">
                                    <div class="layui-inline layui-col-md4">
                                        <input type="hidden" id="indicatorId" name="indicatorId" data-th-value="${indicator.indicatorId}" />
                                        <label class="layui-form-label website-form-item-require">名称:</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="name" autocomplete="off" lay-verify="required" data-th-value="${indicator.name}" class="layui-input" >
                                        </div>
                                    </div>
                                    <div class="layui-inline layui-col-md4">
                                        <label class="layui-form-label website-form-item-require">权重:</label>
                                        <div class="layui-input-inline">
                                            <input type="number" name="weight" autocomplete="off" lay-verify="required" data-th-value="${indicator.weight}" class="layui-input" >
                                        </div>
                                    </div>
                                    <div class="layui-inline layui-col-md4">
                                        <label class="layui-form-label website-form-item-require">描述:</label>
                                        <div class="layui-input-inline">
                                            <textarea name="description" rows="3" maxlength="80"  lay-verify="required" th:text="${indicator.description}" class="layui-textarea"></textarea>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="center">
                            <div class="layui-btn website-hide" id="query"/>
                            <button class="layui-btn" lay-submit="" lay-filter="indicator-update-form-submit" id="submit">保存</button>
                        </div>
                    </form>
                    <div class="table-action-area">
                        <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain table-action" id="indicatorDetailAdd">
                            新增选项
                        </div>
                    </div>
                    <div class="layui-row">
                        <table lay-filter="indicatorDeatilTableUpdate" lay-data="{id: 'indicatorDeatilTableUpdate'}"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="standard-detail-option">
    <a lay-event="edit" shiro:hasPermission="standard:update" class="website-blue">修改</a>
    <a lay-event="del" shiro:hasPermission="standard:delete" class="website-red">删除</a>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['jquery', 'form', 'table', 'website'], function () {
        var $ = layui.jquery,
            website = layui.website,
            form = layui.form,
            table = layui.table,
            $view = $('#website-indicator-update'),
            $indicatorDetailAdd = $view.find('#indicatorDetailAdd'),
            $searchForm = $view.find('form'),
            $query = $view.find('#query'),
            sortObject = {field: 'createTime', type: null},
            tableIns,
            createTimeFrom,
            createTimeTo,
            validate = layui.validate;
        form.verify(validate);
        initTable();
        form.render();
        form.on('submit(indicator-update-form-submit)', function (data) {
            var dateSoure=data.field;
            website.post(ctx + 'indicator/update',dateSoure, function () {
                layer.closeAll();
                //跳转到第一页面
                var currentUrl = window.location.hash.replace('#', '');
                website.view.tab.del(currentUrl);
                window.location.reload();
            });
            return false;
        });
        table.on('tool(indicatorDeatilTableUpdate)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'del') {
                website.modal.confirm('删除信息', '确定删除该信息？', function () {
                    website.post(ctx + 'indicatorDetail/delete/' + data.indicatorDetailId, null, function () {
                        website.alert.success('删除成功');
                        $query.click();
                    });
                });
            };
            if (layEvent === 'edit') {
                website.modal.open('修改信息', 'biz/indicatorDetail/indicatorDetailUpdate/' + data.indicatorDetailId, {
                    area: $(window).width() <= 750 ? '90%' : '50%',
                    offset: '30px',
                    btn: ['提交', '取消'],
                    yes: function (index, layero) {
                        $('#website-indicator-detail-update').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        $query.click();
                        layer.closeAll();
                    }
                });

            }
        });
        table.on('sort(indicatorDeatilTableUpdate)', function (obj) {
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });
        function initTable() {
            tableIns = website.table.init({
                elem: $view.find('table'),
                id: 'indicatorDeatilTableUpdate'
                ,limit: 10
                , url: ctx + 'indicatorDetail/list'
                ,cols: [[
                    {type: 'numbers', title: '序号'},
                    {field: 'indicatorType', title: '级别', minWidth: 100},
                    {field: 'questionDescription', title: '描述', minWidth: 100},
                    {field: 'maxScore', title: '最大分值', minWidth: 100},
                    {field: 'minScore', title: '最小分值', minWidth: 100},
                    {title: '操作',align:'center', toolbar: '#standard-detail-option', minWidth: 200}
                ]],
                where : {
                    indicatorId : $("#indicatorId").val(),
                }
            });
        }
        function getQueryParams() {
            var params = $searchForm.serializeJson();
            var createTime = params.time;
            if (createTime) {
                createTimeFrom = createTime.split(' - ')[0];
                createTimeTo = createTime.split(' - ')[1];
            }
            params.invalidate_ie_cache = new Date();
            params.createTimeFrom = createTimeFrom;
            params.createTimeTo = createTimeTo;
            params.indicatorId = $("#indicatorId").val();
            return params;
        }
        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });
        $indicatorDetailAdd.on('click', function () {
            var cacheDataDel = table.cache["indicatorDeatilTableUpdate"];
            if(cacheDataDel.length==7){
                website.alert.error('最多只允许添加7条数据');
                return false;
            }
            website.modal.open('新增评审标准选项', 'biz/indicatorDetail/indicatorDetailAdd/'+$("#indicatorId").val(), {
                btn: ['提交', '重置'],
                area: $(window).width() <= 750 ? '90%' : '50%',
                offset: '30px',
                scrollbar: true,
                yes: function (index, layero) {
                    $('#website-indicator-add').find('#submit').trigger('click');
                },
                btn2: function () {
                    $('#website-indicator-add').find('#reset').trigger('click');
                    return false;
                }
            });
        });
        function getQueryParams() {
            var params = $searchForm.serializeJson();
            var createTime = params.time;
            if (createTime) {
                createTimeFrom = createTime.split(' - ')[0];
                createTimeTo = createTime.split(' - ')[1];
            }
            params.invalidate_ie_cache = new Date();
            params.createTimeFrom = createTimeFrom;
            params.createTimeTo = createTimeTo;
            return params;
        }
    })
</script>